package com.lyp.mvpsupermanage.user.presenter;

import android.util.Log;

import com.blankj.utilcode.util.ToastUtils;
import com.lyp.mvpsupermanage.network.ApiCallback;
import com.lyp.mvpsupermanage.network.bean.LoginBean;

import java.util.List;

/**
 * 作者:ChenXi 时间:2017/8/1 16: 30
 */

public class LoginPresenter extends BasePresenter<LoginView>{

    public LoginPresenter(LoginView view){
        attachView(view);
    }

    //登录
    public void Login(String user,String pwd){
      mvpView.showLoading();
      addSubscription(apistores.getLogin(pwd, user), new ApiCallback<LoginBean>() {
          @Override
          public void onSuccess(LoginBean model) {
              mvpView.getLoginSuccess(model);
              if (model.getResult() == 1 ){
                  List<LoginBean.DataBean> dataBeen = model.getData();
                  ToastUtils.showShort(model.getMessage());
                  Log.i("tag",model.getMessage()+"__");

              }
              else {
                  ToastUtils.showShort("登录失败！请检查用户名或密码是否正确！");
              }
          }

          @Override
          public void onFailure(String msg) {
              mvpView.getLoginFail(msg);
          }

          @Override
          public void onFinish() {
              mvpView.hideLoading();
          }
      });
    }

}
